xlv.obj.schedule={
	extend:function(){
	},
	implement:function(){
	},
	pub:{
		weekNames:['SUN','MON','TUE','WEN','THR','FRI','SAT'],
		monthNames:['January','February','March','April','May','June','July','August','September','October','November','December']
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.schedule');
		return div;			
	},
	properties:{
		initialDate:null,
		weekNames:null,
		monthNames:null,
		showCurrentMonthOnly:false,
		dayWidth:'70px',
		dayHeight:'60px'
	},
	method:{
		construct:function(){
			var v=this.$V,p=this.$P;
			Element.addClassName(this,'classs_schedule');
			if(!p.weekNames) p.weekNames=xlv.obj.schedule.pub.weekNames;
			if(!p.monthNames) p.monthNames=xlv.obj.schedule.pub.monthNames;
			//
			v.wpattern=xlv.util.findDirectChild(this, {id:'xlvid_schedule_week'},null);
			if(v.wpattern){
				v.wpattern.parentNode.removeChild(v.wpattern);
				xlv.sys._clearExtendedFlag(v.wpattern);
			}else{
				var prop={border:{enable:true,borderColor:null,background:null,style:'top'}};
				var pane=xlv.sys.newObject('pane',prop);
				pane.setAttribute('id','xlvid_schedule_week');
				var root= pane.getRootPane();
				var style={background:'url(/xlive/images/grayTexture.gif) left top repeat'};
				Element.setStyle(root,style);
				var name=xlv.sys.newObject('viewer',null,null,'div');
				name.setAttribute('id','xlvid_schedule_weekname');
				root.appendChild(name);
				v.wpattern=pane;
			}
			//
			v.pattern=xlv.util.findDirectChild(this, {id:'xlvid_schedule_day'},null);
			if(v.pattern){
				v.pattern.parentNode.removeChild(v.pattern);
				xlv.sys._clearExtendedFlag(v.pattern);
			}else{
				var prop={border:{enable:true,borderColor:null,background:'none',style:'all'}};
				var pane=xlv.sys.newObject('pane',prop);
				pane.setAttribute('id','xlvid_schedule_day');
				var root= pane.getRootPane();
				var style={width:p.dayWidth,height:p.dayHeight,background:'url(/xlive/images/grayTexture.gif) left top repeat'};
				Element.setStyle(root,style);
				var date=xlv.sys.newObject('viewer',null,null,'div');
				date.setAttribute('id','xlvid_schedule_date');
				root.appendChild(date);
				var content=xlv.sys.newObject('viewer',null,null,'div');
				content.setAttribute('id','xlvid_schedule_content');
				root.appendChild(content);
				v.pattern=pane;
			}
			var div,sep;
			//montharea
			this.appendChild(div=v.montharea=document.createElement('div'));
			v.montharea.setAttribute('id','xlvid_schedule_montharea');
			Element.setStyle(v.montharea,{position:'relative',overflow:'hidden'});
			//
			div.appendChild(v.month=document.createElement('div'));
			v.month.setAttribute('id','xlvid_schedule_month');
			Element.setStyle(v.month,{align:'center'});
			this.styleForId(v.month,v.month.id);
			
			div.appendChild(v.year=document.createElement('div'));
			v.year.setAttribute('id','xlvid_schedule_year');
			Element.setStyle(v.year,{position:'absolute'});
			this.styleForId(v.year,v.year.id);
			div.appendChild(v.cyear=document.createElement('div'));
			v.cyear.setAttribute('id','xlvid_schedule_cyear');
			Element.setStyle(v.cyear,{position:'absolute'});
			this.styleForId(v.cyear,v.cyear.id);
			//
			div.appendChild(v.tool=document.createElement('div'));
			v.tool.setAttribute('id','xlvid_schedule_tool');
			if(Prototype.Browser.IE) {
				var style={background :'url("/xlive/images/almost_transparent.png") top left repeat'};
				Element.setStyle(v.tool,style);
			}
			v.tool.appendChild(v.prevYear=document.createElement('img'));
			v.prevYear.setAttribute('id','xlvid_schedule_prevyear');
			v.prevYear.setAttribute('src','/xlive/images/schedule/left_fast.png');
			this.styleForId(v.prevYear,v.prevYear.id);
			Element.setStyle(v.prevYear,{position:'absolute'});
			
			v.tool.appendChild(v.prevMonth=document.createElement('img'));
			v.prevMonth.setAttribute('id','xlvid_schedule_prevmonth');
			v.prevMonth.setAttribute('src','/xlive/images/schedule/left.png');
			this.styleForId(v.prevMonth,v.prevMonth.id);
			Element.setStyle(v.prevMonth,{position:'absolute'});
			
			v.tool.appendChild(v.nextMonth=document.createElement('img'));
			v.nextMonth.setAttribute('id','xlvid_schedule_nextmonth');
			v.nextMonth.setAttribute('src','/xlive/images/schedule/right.png');
			this.styleForId(v.nextMonth,v.nextMonth.id);
			Element.setStyle(v.nextMonth,{position:'absolute'});
			
			v.tool.appendChild(v.nextYear=document.createElement('img'));
			v.nextYear.setAttribute('id','xlvid_schedule_nextyear');
			v.nextYear.setAttribute('src','/xlive/images/schedule/right_fast.png');
			this.styleForId(v.nextYear,v.nextYear.id);
			Element.setStyle(v.nextYear,{position:'absolute'});
			//dayarea
			this.appendChild(div=v.mask=document.createElement('div'));
			Element.setStyle(div,{position:'relative',overflow:'hidden'});
			div.appendChild(v.dayarea=document.createElement('div'));
			v.dayarea.setAttribute('id','xlvid_schedule_dayarea');
			Element.setStyle(v.dayarea,{position:'relative'});
			this.styleForId(v.dayarea,v.dayarea.id);
			//
			var row,col;
			v.dayarea.appendChild(v.table=document.createElement('table'));
			v.table.setAttribute('id','xlvid_schedule_table');
			v.table.setAttribute('cellpadding','0px');
			v.table.setAttribute('cellspacing','0px');
			this.styleForId(v.table,v.table.id);
			//
			v.table.appendChild(v.tbody=document.createElement('tbody'));
			v.tbody.setAttribute('id','xlvid_schedule_body');
			v.weeks=[];
			v.tbody.appendChild(row=document.createElement('tr'));
			for(var i=0;i<7;++i){
				row.appendChild(col=document.createElement('td'));
				v.tbody.setAttribute('id','xlvid_schedule_weektd');
				var object=v.wpattern.cloneNode(true);
				col.appendChild(object);
				col.style.borderBottom='solid white 1px';
				if(Prototype.Browser.IE) xlv.sys._patchIEProperties(object);
				else{if(!object._$extended)xlv.sys.extend(object);}
				v.weeks[v.weeks.length]=xlv.util.findChild(object,{id:'xlvid_schedule_weekname'},false,false);
				if(i==0)Element.addClassName(object,'sun');
				if(i==6)Element.addClassName(object,'sat');
				this.styleForId(object,object.id);
			}
			v.days=[];
			v.dates=[];
			v.contents=[];
			for(var i=0;i<6;++i){
				v.tbody.appendChild(row=document.createElement('tr'));
				for(var d=0;d<7;++d){
					row.appendChild(col=document.createElement('td'));
					col.setAttribute('id','xlvid_schedule_daytd');
					var object=v.pattern.cloneNode(true);
					col.appendChild(object);
					if(Prototype.Browser.IE) xlv.sys._patchIEProperties(object);
					else{if(!object._$extended)xlv.sys.extend(object);}
					v.days[v.days.length]=object;
					v.dates[v.dates.length]=xlv.util.findChild(object,{id:'xlvid_schedule_date'},false,false);
					v.contents[v.contents.length]=xlv.util.findChild(object,{id:'xlvid_schedule_content'},false,false);
					col.appendChild(object);
					if(d==0)Element.addClassName(object,'sun');
					if(d==6)Element.addClassName(object,'sat');
					this.styleForId(object,object.id);
					if(v.days.length==38)break;
				}
			}
		},
		initial:function(){
			var p=this.$P,v=this.$V;
			this.valueToWeekNames();
			var w=v.days[0].offsetWidth*7;
			if(v.table.offsetWidth>w)w=v.table.offsetWidth;
			Element.setStyle(v.montharea,{width:w+'px'});
			Element.setStyle(v.mask,{width:w+'px'});
			//
			v.current=v.past=(p.initialDate)? p.initialDate:new Date();
			if(p.dateString) v.current.parseDate(p.dateString);
			this.setDate(v.current);
			this.addEventHandler('mousedown','_mousedown',v.nextMonth);
			this.addEventHandler('mousedown','_mousedown',v.prevMonth);
			this.addEventHandler('mousedown','_mousedown',v.nextYear);
			this.addEventHandler('mousedown','_mousedown',v.prevYear);
			this.addEventHandler('mousedown','_dayClick',v.dayarea);
			
			this.addEventHandler('mouseover','_toolMouseOver',v.montharea);
			this.addEventHandler('mouseout','_toolMouseOut',v.tool);
			
		},
		styleForId:function(tag,id){
		},
		_mousedown:function(event){
			var v=this.$V;
			var to=new Date(v.current.getTime());
			var from=new Date(v.current.getTime());
			if(event.target.id=='xlvid_schedule_prevmonth'){
				to.setMonth(to.getMonth()-1);
				this.effect(from,to);
			}
			if(event.target.id=='xlvid_schedule_nextmonth'){
				to.setMonth(to.getMonth()+1);
				this.effect(from,to);
			}
			if(event.target.id=='xlvid_schedule_prevyear'){
				to.setFullYear(to.getFullYear()-1);
				this.effect(from,to);
			}
			if(event.target.id=='xlvid_schedule_nextyear'){
				to.setFullYear(to.getFullYear()+1);
				this.effect(from,to);
			}
		},
		_dayClick:function(event){
			var target=this.targetElement(event.target,{id:'xlvid_schedule_day'},{object:this});
			if(target &&!Element.hasClassName(target,'disabled')){
				if(this.$V.selectedDay)	Element.removeClassName(this.$V.selectedDay,'selected');
				this.$V.selectedDay=target;
				Element.addClassName(this.$V.selectedDay,'selected');
				this.$V.selectedDate=new Date(target.$V._date.getTime());
				this.dayClick(target.$V._date.cloneDate(),target);
			}
		},
		dayClick:function(date,dayobject){
		},
		calendarChanged:function(from,to){
		},
		getCurrentDate:function(){
			return this.$V.current.cloneDate();
		},
		getSelectedDate:function(){
			return this.$V.selectedDate;
		},
		getDayObjectArray:function(){
			return this.$V.days;
		},
		getContentObjectArray:function(){
			return this.$V.contents;
		},
		effect:function(from,to){
			var v=this.$V;
			if(this.$V.effecting) return;
			this.$V.effecting=true;
			var go={element:v.dayarea,minPx:4};
			if(from>to) go.style={left:(0-v.dayarea.offsetWidth)+'px'};
			else go.style={left:(v.dayarea.offsetWidth)+'px'};
			var back={element:v.dayarea,minPx:4};
			back.style={left:'0px'};
			back.finished=function(){
				v.effecting=false;
			};
			go.finished=(function(){
				if(from>to)v.dayarea.style.left=v.dayarea.offsetWidth+'px';
				else v.dayarea.style.left=(0-v.dayarea.offsetWidth)+'px';
				this.setDate(to);
				xlv.util.styleEffect(back);
			}).bind(this);
			xlv.util.styleEffect(go);
		},
		valueToWeekNames:function(){
			for(var i=0;i<7;++i){
				var week=this.$V.weeks[i];
				if(week['isExtend']&&week.isExtend('xlv.obj.viewer')) week.mvc_valueToView(this.$P.weekNames[i]);
				else xlv.util.setElementValue(week,this.$P.weekNames[i]);
			}
		},
		valueToMonth:function(month,month_name){
			xlv.util.setElementValue(this.$V.month,month_name);
		},
		valueToYear:function(year){
			xlv.util.setElementValue(this.$V.year,year);
		},
		valueToCYear:function(cyear){
			if(this.$V.cyear)xlv.util.setElementValue(this.$V.cyear,cyear);
		},
		setDate:function(todate){
			var v=this.$V;
			v.past=v.current.cloneDate();
			v.current=todate.cloneDate();
			var dd=new Date(v.current.getTime());
			dd.setDate(1);
	        var first=dd.getDay();
	        var last=new Date(dd.getFullYear(),dd.getMonth()+1,1,0,0,0,0);
	        last=new Date(last.getTime()-3600*1000).getDate();
	        var now=new Date();
	        if(v.today){
	        	Element.removeClassName(v.today,'today');
	        	v.today=null;
	        }
	        if(v.selectedDay){
	        	Element.removeClassName(v.selectedDay,'selected');
	        	v.selectedDay=null;
	        }
	        var sel_date=v.selectedDate;
	        dd=new Date(dd.getTime()-(86400000*first));
	        for(var i=0;i<v.days.length;++i) {
	        	var day=v.days[i];
	        	var date=v.dates[i];
	        	var content=v.contents[i];
	        	if(dd.getDate()==now.getDate()&& dd.getMonth()==now.getMonth()&&dd.getFullYear()==now.getFullYear()){
	        		Element.addClassName(day,'today');
	        		v.today=day;
	        	}
	        	//
	        	if(sel_date&&dd.getDate()==sel_date.getDate()&& dd.getMonth()==sel_date.getMonth()&&dd.getFullYear()==sel_date.getFullYear()){
	        		 Element.addClassName(day,'selected');
	        		 v.selectedDay=day;
	        	}
	        	//
        		if(date['isExtend']&&date.isExtend('xlv.obj.viewer')) {
        			date.mvc_valueToView(dd.getDate());
        			date.$V._date=dd.cloneDate();
        		}else xlv.util.setElementValue(date,dd.getDate());
        		if(day['extend']) day.$V._date=dd.cloneDate();
        		if(content['extend'])content.$V._date=dd.cloneDate();
        		//
	        	if(i<first){
	        		Element.addClassName(day,'disabled');
	        		day.style.visibility= (this.$P.showCurrentMonthOnly) ? 'hidden':'visible';
	        		if(Prototype.Browser.IE7)Element.setStyle(day,{opacity:'0.7'});
	        	}else if((i-first+1)>last){
	        		Element.addClassName(day,'disabled');
	        		if(Prototype.Browser.IE7)Element.setStyle(day,{opacity:'0.7'});
	        		if(i>=35)day.style.visibility='hidden';
	        		else day.style.visibility=(this.$P.showCurrentMonthOnly)? 'hidden':'visible';
	        	}else{
	        		if(Prototype.Browser.IE7)Element.setStyle(day,{opacity:'1'});
	        		Element.removeClassName(day,'disabled');
	        		day.style.visibility='visible';
	        	}
	        	dd=new Date(dd.getTime()+86400000);
	        }
	        this.valueToYear(v.current.getFullYear());
	        this.valueToCYear(v.current.getFullYear()-1911);
	        this.valueToMonth(v.current.getMonth()+1,this.$P.monthNames[v.current.getMonth()]);
	        if(v.past.getMonth()!=v.current.getMonth() || v.past.getFullYear()!=v.current.getFullYear())
	        	this.calendarChanged(v.past.cloneDate(),v.current.cloneDate());
		},
		_showTool:function(visible){
			this.$V.toolEffecting=true;
			var options={element:this.$V.tool,minPx:(Prototype.Browser.IE)?10:4};
			if(visible){
				options.style={bottom:'0px'};
				options.finished=(function(){this.$V.toolEffecting=false;}).bind(this);
				xlv.util.styleEffect(options);
				this.$V.toolVisible=true;
			}else{
				this.$V.toolVisible=false;
				options.style={bottom:(0-this.$V.tool.offsetHeight)+'px'};
				options.finished=(function(){this.$V.toolEffecting=false;}).bind(this);
				xlv.util.styleEffect(options);
			}
		},
		_toolMouseOver:function(event){
			if(this.$V.toolEffecting||this.$V.toolVisible) return;
			var target=this.targetElement(event.target,{id:'xlvid_schedule_montharea'});
			if(target==this.$V.montharea) this._showTool(true);
		},
		_toolMouseOut:function(event){
			if(this.$V.toolEffecting||!this.$V.toolVisible) return;
			var to=(event.toElement||event.relatedTarget);
			if((to && !xlv.util.isDescendantOf(to,this.$V.tool)))this._showTool(false);
		}


	}
};
